package com.java1412.goods.controller;

import com.java1412.goods.service.GoodsService;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * 商品相关接口
 *
 * @author java1412
 * @since 2024-04-23 16:46:11
 */
@RestController
@RequestMapping("/api/v1/goods")
public class GoodsController {

    @Value("${server.port}")
    private String port;

    @Resource
    private GoodsService goodsService;

    @RequestMapping(value = "/findByGoodsId")
    public Object findByGoodsId(Integer goodsId) {
        System.out.println(port);
        return goodsService.findById(goodsId);
    }

    // 测试负载均衡机制
    @RequestMapping(value = "/findClusterName")
    public Object findClusterName(HttpServletRequest request) {
        // 获取哪个节点被请求到
        String clusterName = "当前服务器名称:" + request.getServerName()
                + ";当前集群节点的端口号:" + request.getServerPort();
        return clusterName;
    }
}
